package com.xy.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;


public class XmlUtil {
    public static Document getElement(File file) {
        Document doc = null;
        try{
            SAXReader reader = new SAXReader();
            doc = reader.read(file);
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }
        return doc;
    }
    public static void saveElement(Document document,String filePath)throws IOException {
        OutputFormat format=OutputFormat.createCompactFormat();
        format.setEncoding("utf-8");

        XMLWriter writer =new XMLWriter(new FileOutputStream(new File(filePath)),format);
        writer.write(document);
        writer.close();
        System.out.println("Document.Xml......保存完成......"+filePath);
    }
}
